#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdbool.h>

//https://leetcode.cn/problems/invert-binary-tree/submissions/417885208/
struct TreeNode {
   int val;
   struct TreeNode *left;
   struct TreeNode *right;
};


struct TreeNode* invertTree(struct TreeNode* root) {
    if (root == NULL)
        return;
    if (root->left || root->right)
    {
        struct TreeNode* tem = root->left;
        root->left = root->right;
        root->right = tem;
        invertTree(root->left);
        invertTree(root->right);
    }
    return root;
}